<?php defined('BASEPATH') or exit('No direct script access allowed');

class Example extends FrontendController {

	function __construct()
	{
		parent::__construct();

		$this->load->helper('url');
	}

	public function index()
	{
		$this->output->set_title(lang('site_name'));
		
		$items = $this->db->order_by('id DESC')->get('content')->result();
		foreach($items as $item)
		{
			$data = array();
			$data['id'] = $item->id;
			$data['title'] = $item->title;
			$data['alias'] = $item->alias;
			$data['category_id'] = $item->catid;
			$data['description'] = strip_tags($item->introtext);
			$data['content'] = $item->introtext.$item->fulltext;
			if (preg_match("/\<img[^\>\r\n]*?src=[\'\"]([^\'\"\>\r\n]+?)[\'\"][^\>]*?\>/", $data['content'], $matches))
			{
				if ($matches)
				{
					$data['image'] = $matches[1];
				}
			}
			$data['created_by'] = 1;
			$data['created_by_alias'] = $item->created_by_alias;
			$data['created_time'] = $item->created;
			$data['modified_time'] = $item->modified;
			$data['hits'] = $item->hits;
			$data['tag'] = $item->metakey;
			$data['published'] = 1;
			$this->db->insert('posts', $data);
		}
		
		$this->output->set_template('default');
		$this->load->view('homepage');
	}

	public function example_1()
	{
		$this->load->view('ci_simplicity/example_1');
	}

	public function example_2()
	{
		$this->output->set_template('simple');
		$this->load->view('ci_simplicity/example_2');
	}

	public function example_3()
	{
		$this->load->section('sidebar', 'ci_simplicity/sidebar');
		$this->load->view('ci_simplicity/example_3');
	}

	public function example_4()
	{
		$this->output->unset_template();
		$this->load->view('ci_simplicity/example_4');
	}
}
